package process;

import java.util.Collection;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import entity.Profile;

public class ProfileProcess extends EntityProcess {
	
	public Collection<Profile> getProfileByGroup(Long id)throws Exception{
		EntityManager em = this.getEntityManager();
		try{			
			Query q = em.createQuery("SELECT p FROM "+Profile.class.getName()+" p WHERE P.groupId=?1");
			q.setParameter(1, id);
			
		    @SuppressWarnings("unchecked")
			List<Profile> results = q.getResultList();			
			return results;
		}
		catch(Exception ex){
			throw ex;//this.LogException(ex);
		}
		finally{
			this.releaseEntityManager(em);
		}
	}
	public Collection<Profile> getProfileByServer(Long id)throws Exception{
		EntityManager em = this.getEntityManager();
		try{			
			Query q = em.createQuery("SELECT p FROM "+Profile.class.getName()+" p WHERE P.serverId=?1");
			q.setParameter(1, id);
			
		    @SuppressWarnings("unchecked")
			List<Profile> results = q.getResultList();			
			return results;
		}
		catch(Exception ex){
			throw ex;//this.LogException(ex);
		}
		finally{
			this.releaseEntityManager(em);
		}
	}
}
